package com.sanjiahantang.youjiaclient.module.common.views.impl;

import android.content.Intent;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanjiahantang.youjiaclient.R;
import com.sanjiahantang.youjiaclient.base.BaseMvpActivity;
import com.sanjiahantang.youjiaclient.base.BaseMvpPresenter;
import com.sanjiahantang.youjiaclient.base.BaseView;
import com.sanjiahantang.youjiaclient.module.common.presenters.BindRolePresenter;
import com.sanjiahantang.youjiaclient.module.common.presenters.MainPresenter;
import com.sanjiahantang.youjiaclient.module.common.views.MainView;


/**
 * Created by zy on 2017/9/8.
 * 手动录入编码
 */

public class ManulInputActivity extends BaseMvpActivity<BaseView,BindRolePresenter> implements BaseView, TextWatcher, View.OnClickListener {

    private EditText etCode;
    private View flGo;
    private ImageView ivGo;
    private int colorEnable,colorAble;
    @Override
    public BindRolePresenter initPresenter() {
        return new BindRolePresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_manul_input);
        etCode = (EditText) findViewById(R.id.etCode);
        etCode.addTextChangedListener(this);
        flGo = findViewById(R.id.flGo);
        ivGo = (ImageView) findViewById(R.id.ivGo);

        colorEnable = getResources().getColor(R.color.gray_de);
        colorAble = getResources().getColor(R.color.colorPrimary);

        TextView title = (TextView) findViewById(R.id.title);
        title.setText("手动输入");

        findViewById(R.id.back).setOnClickListener(this);
        flGo.setOnClickListener(this);
        flGo.setClickable(false);
    }

    @Override
    public void initData() {

    }

    @Override
    public void showProgress() {

    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if(!TextUtils.isEmpty(s)){
            flGo.setBackgroundColor(colorAble);
            ivGo.setImageResource(R.drawable.i_next_white);
            flGo.setClickable(true);
        }else {
            flGo.setBackgroundColor(colorEnable);
            ivGo.setImageResource(R.drawable.i_next_black);
            flGo.setClickable(false);
        }
    }

    @Override
    public void afterTextChanged(Editable s) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                finish();
                break;
            case R.id.flGo:
                presenter.bindRole($this,etCode.getText().toString());
                break;
        }
    }
}
